package com.zhongya.example.view.second

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout

class CustomLinearLayout : LinearLayout {

    val colorMatrix = ColorMatrix(
            floatArrayOf(
                    0.213f,0.715f,0.072f,0f,0f,
                    0.213f,0.715f,0.072f,0f,0f,
                    0.213f,0.715f,0.072f,0f,0f,
                    0f,0f,0f,1f,0f,
            )
    )

    var mBitmap : Bitmap? = null
    var mCanvas : Canvas? = null
    var mPaint : Paint? = null



    constructor(context: Context) : super(context) {

    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {


    }

    override fun dispatchDraw(canvas: Canvas?) {

        if (mBitmap == null){
            mBitmap = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888)
            mCanvas = Canvas(mBitmap!!)
            mPaint = Paint()
            mPaint?.colorFilter = ColorMatrixColorFilter(colorMatrix)
        }
        canvas?.save()

        super.dispatchDraw(mCanvas)

        canvas?.drawBitmap(mBitmap!!,0f,0f,mPaint)
        canvas?.restore()
    }

    override fun onTouchEvent(event: MotionEvent?): Boolean {
        return super.onTouchEvent(event)
    }

    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        return super.onInterceptTouchEvent(ev)
    }




}